if __name__ == '__main__':
    # 递归算法_二叉树的前序遍历PreorderTraversalofBinaryTree
    class TreeNode:
        def __init__(self, x):
            self.value = x
            self.left = None
            self.right = None


    def preorder_traversal(root):
        # 基线条件
        if root is None:
            return
        # 递归条件
        else:
            print(root.value)  # 访问根节点
            preorder_traversal(root.left)  # 递归遍历左子树
            preorder_traversal(root.right)  # 递归遍历右子树

    # 示例
    root = TreeNode(1)
    root.right = TreeNode(2)
    root.right.left = TreeNode(3)
    preorder_traversal(root)